package com.pic.others.mq;


import com.pic.common.constants.MqConstants;
import com.pic.others.config.minio.MinIOConfigProperties;
import com.pic.others.config.minio.MinIOUtil;
import com.pic.others.mq.message.EmailMessage;
import com.pic.others.service.ICodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@RequiredArgsConstructor
@Component
@Slf4j
public class NoteListerner {

    @Value("${minio.bucket}")
    String bucket;
    @Autowired
    private MinIOConfigProperties minIOConfigProperties;


    private final MinIOUtil minIOUtil;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "qa.note.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.NOTE_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.NOTE_DELETE_KEY
    ))
    public void deleteLocate(List<String> lcoates){
        for(String locate:lcoates){
            minIOUtil.deleteFile(bucket,minIOConfigProperties.getReadPath()+locate);
        }
    }


}

